package com.fuhailiu.opengl.config;

import java.util.ArrayList;

import android.content.Context;

import com.fuhailiu.opengl.R;
import com.fuhailiu.opengl.define.AppGlobalDef;
import com.fuhailiu.opengl.renders.AbsRender;
import com.fuhailiu.opengl.renders.RenderBlend;
import com.fuhailiu.opengl.renders.RenderCube;
import com.fuhailiu.opengl.renders.RenderFBO;
import com.fuhailiu.opengl.renders.RenderPBOPack;
import com.fuhailiu.opengl.renders.RenderPBOUnPack;
import com.fuhailiu.opengl.renders.RenderPointLine;
import com.fuhailiu.opengl.renders.RenderPolygonOffset;
import com.fuhailiu.opengl.renders.RenderScissor;
import com.fuhailiu.opengl.renders.RenderSixPointedStar;
import com.fuhailiu.opengl.renders.RenderTexture2D;
import com.fuhailiu.opengl.renders.RenderTriangle;
import com.fuhailiu.opengl.renders.RenderTriangleFan;
import com.fuhailiu.opengl.renders.RenderTriangleStrip;
import com.fuhailiu.opengl.renders.RenderVAO;
import com.fuhailiu.opengl.renders.RenderVBO;
import com.fuhailiu.opengl.utils.LogUtil;

public class ItemDataManager {

	private static final String TAG = ItemDataManager.class.getSimpleName();

	private static final int[] RES_IDS = new int[] { 
		R.string.item_point_line, 
		R.string.item_triangle, 
		R.string.item_triangle_strip, 
		R.string.item_triangle_fan, 
		R.string.item_cube, 
		R.string.item_texture, 
		R.string.item_six_pointed_star, 
		R.string.item_polygon_offset, 
		R.string.item_scissor, 
		R.string.item_blend, 
		R.string.item_vbo, 
		R.string.item_vao, 
		R.string.item_pbo_pack, 
		R.string.item_pbo_unpack, 
		R.string.item_fbo, 
		};

	private static final int[] RENDER_IDS = new int[] { 
		AppGlobalDef.RenderIds.RENDER_POINT_LINE, 
		AppGlobalDef.RenderIds.RENDER_TRIANGLE, 
		AppGlobalDef.RenderIds.RENDER_TRIANGLE_STRIP, 
		AppGlobalDef.RenderIds.RENDER_TRIANGLE_FAN, 
		AppGlobalDef.RenderIds.RENDER_CUBE, 
		AppGlobalDef.RenderIds.RENDER_TEXTURE, 
		AppGlobalDef.RenderIds.RENDER_SIX_POINTED_START, 
		AppGlobalDef.RenderIds.RENDER_POLYGON_OFFSET, 
		AppGlobalDef.RenderIds.RENDER_SCISSOR, 
		AppGlobalDef.RenderIds.RENDER_BLEND, 
		AppGlobalDef.RenderIds.RENDER_VBO, 
		AppGlobalDef.RenderIds.RENDER_VAO, 
		AppGlobalDef.RenderIds.RENDER_PBO_PACK, 
		AppGlobalDef.RenderIds.RENDER_PBO_UNPACK, 
		AppGlobalDef.RenderIds.RENDER_FBO, 
		};

	public static ArrayList<ItemData> getItemDataList() {
		ArrayList<ItemData> result = new ArrayList<ItemData>();

		if (RES_IDS.length != RENDER_IDS.length) {
			LogUtil.LogE(TAG, "length of res array and render array is not equal");
		} else {
			int length = RES_IDS.length;
			for (int i = 0; i < length; i++) {
				ItemData item = new ItemData();
				item.resId = RES_IDS[i];
				item.renderId = RENDER_IDS[i];
				result.add(item);
			}
		}

		return result;
	}

	public static AbsRender getRenderById(Context context, int renderId) {
		AbsRender render = null;

		switch (renderId) {
		case AppGlobalDef.RenderIds.RENDER_POINT_LINE:
			render = new RenderPointLine(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_TRIANGLE:
			render = new RenderTriangle(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_TRIANGLE_STRIP:
			render = new RenderTriangleStrip(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_TRIANGLE_FAN:
			render = new RenderTriangleFan(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_CUBE:
			render = new RenderCube(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_TEXTURE:
			render = new RenderTexture2D(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_SIX_POINTED_START:
			render = new RenderSixPointedStar(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_POLYGON_OFFSET:
			render = new RenderPolygonOffset(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_SCISSOR:
			render = new RenderScissor(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_BLEND:
			render = new RenderBlend(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_VBO:
			render = new RenderVBO(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_VAO:
			render = new RenderVAO(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_PBO_PACK:
			render = new RenderPBOPack(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_PBO_UNPACK:
			render = new RenderPBOUnPack(context);
			break;

		case AppGlobalDef.RenderIds.RENDER_FBO:
			render = new RenderFBO(context);
			break;
		}

		return render;
	}

}
